#include "chatmessagetoserver.h"


ChatMessageToServer::ChatMessageToServer(const UserId& userId, const FriendId& friendId,
                    const ChatMessage& chatMsg, const CreateTime& sendTime)
{
    m_messageType = MessageType::ChatMessageToServer;
    m_userId = userId;
    m_friendId = friendId;
    m_chatMessage = chatMsg;
    m_sendTime = sendTime;
}

ChatMessageToServer::ChatMessageToServer(const QJsonObject& jsonObj)
{
    m_messageType = static_cast<MessageType>(jsonObj[JsonKey::TYPE].toInt());
    m_userId = jsonObj[JsonKey::USER_ID].toString();
    m_friendId = jsonObj[JsonKey::FRIEND_ID].toString();
    m_chatMessage = jsonObj[JsonKey::CHAT_MSG].toString();
    m_sendTime = jsonObj[JsonKey::CREATE_TIME].toString();
}

QJsonObject ChatMessageToServer::PackJsonData() const
{
    QJsonObject jsonObj;
    jsonObj[JsonKey::TYPE] = static_cast<int>(m_messageType);
    jsonObj[JsonKey::USER_ID] = m_userId;
    jsonObj[JsonKey::FRIEND_ID] = m_friendId;
    jsonObj[JsonKey::CHAT_MSG] = m_chatMessage;
    jsonObj[JsonKey::CREATE_TIME] = m_sendTime;
    return jsonObj;
}

UserId ChatMessageToServer::getUserId() const
{
    return m_userId;
}

FriendId ChatMessageToServer::getFriendId() const
{
    return m_friendId;
}

ChatMessage ChatMessageToServer::getChatMessage() const
{
    return m_chatMessage;
}

CreateTime ChatMessageToServer::getSendTime() const
{
    return m_sendTime;
}
